package com.xcity.game.rank;

import com.xcity.db.entity.Ranking;

import java.util.Comparator;

public enum RankingComparator implements Comparator<Ranking> {
	
	VALUE_DESC_TIME_ASC {
		@Override
		public int compare(Ranking previous, Ranking next) {
			long val1 = previous.getBufferValue();
			long val2 = next.getBufferValue();
			if (val1 == val2) {
				if (previous.getTime() == next.getTime()) {
					return previous.getId() > next.getId() ? 1 : -1;
				}
				return previous.getTime() > next.getTime() ? 1 : -1;
			}
			return val1 < val2 ? 1 : -1;
		}
	},
	
	VALUE_TIME_DESC {
		@Override
		public int compare(Ranking previous, Ranking next) {
			long val1 = previous.getBufferValue();
			long val2 = next.getBufferValue();
			if (val1 == val2) {
				return previous.getTime() < next.getTime() ? 1 : -1;
			}
			return val1 < val2 ? 1 : -1;
		}
	},
	;
	
}
